package com.changgou.system.service;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.changgou.system.mapper.AdminMapper;
import com.changgou.system.pojo.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.stereotype.Service;

@Service
public class AdminService {

    @Autowired
    private AdminMapper adminMapper;

    public boolean login(Admin admin) {
        //根据登录名查询管理员
        Admin admin1=new Admin();
        admin1.setLoginName(admin.getLoginName());
        admin1.setStatus("1");
        Admin admin2 = adminMapper.selectOne(admin1);//数据库查询出的对象
        if(admin2 == null){
            return false;
        }else{
            //验证密码, Bcrypt为spring的包, 第一个参数为明文密码, 第二个参数为密文密码
            return BCrypt.checkpw(admin.getPassword(),admin2.getPassword());
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Snowflake snowflake = IdUtil.getSnowflake(1, 1);
        for (int i = 0; i < 1000; i++) {
            long id = snowflake.nextId();
            Thread.sleep(3000);
            System.out.println(id);
        }
    }

}
